<?php
namespace Home\Controller;
use Think\Controller;
use Think\Verify;
class IndexController extends Controller {
    
	public function index(){
	   // $name="李欣";
	   //  $this->assign("data",$name);
	   //  $data['verify']=$Verify;
       // $this->assign('$data',$data);
	    $this->display();
	  
	 }
/*  
 * 初始化验证码
 * */
	 public function Verify(){
	     $config = array(
	         'fontSize'=> 20,//验证字体大小
	         'length' => 4,//验证码位数
	         'imageH'=>40,//验证码高度
	         'imageW'=>140,//验证码宽度
	         //'useImgBg'=>false,// 开启验证码背景图片功能
	         'useNoise'=>false,// 关闭验证码杂点
	     );
	     $Verify=new \Think\Verify($config);
	     $Verify->entry(1);
	 }
	/* 
	 * 判断session是否为空
	 *  
	 *  */ 
	 
	 public function verifySession(){

	         if (($_SESSION['user'] != null)) {
	             //echo $_SESSION['user'];
	             $this->display('Start/start');
	         }else if($this->check_username()) {
	             //echo $this->check_username();
	             $this->display('Start/start');
	         }else {
	    
	         $this->display('Index/index');
	         }  
	 }
	 /*
	  * 验证用户信息
	  * @param
	  *
	  */
	 function check_username()
	 {
	     $name = $_POST['username'];
	     $password = $_POST['password'];
	     $code = $_POST['code'];
	     
	     // if ($this->checkverify($code, '')) {
	     //    $this->error("验证码错误！");
	     //    break;
	     //}
	     $User = M('user');
	     // $re = $User->where('username='.$name)->select();
	     $i = $User->where('user="' . $name . '" and password="' . $password . '"')->select();
	   //  dump($i);
	     session("user", $i[0]['user']);
	     session("password", $i[0]['password']);
	    // dump($_SESSION['user']);
	    // dump($_SESSION['password']);
	     
	     if ($i > 0) {
	         return true;
	     } else {
	         return false;
	     }
	 }
	 
/* 
 * 删除session
 *  
 *  */
	 public function destroy(){
	     session('session_id',null);
	     $_SESSION['user']=null;
	    // echo $_SESSION['user'];
	     $this->display('Index/index');
	 }
}